package com.ag.zhh.action;

import java.util.List;

import com.ag.common.BaseAction;
import com.ag.contactTree.service.LocalTreeService;
import com.ag.contactTree.service.TreeService;
import com.ag.zhh.service.ContactService;
import com.ag.zhh.utils.JsonUtil;
import com.ag.zhh.vo.Contact;

public class ContactAction extends BaseAction {

	/**
	 * 
	 * @return
	 */
	private LocalTreeService service;
	public String saveOrUpdateContact() {
		//contactService.saveOrUpdateContact(contact);
		System.out.println(adminIf);
		
		Contact contact = new Contact();
		contact.setCCellphone(cCellPhone);
		contact.setCFax(cFax);
		contact.setCId(cId);
		contact.setCName(cName);
		contact.setCTel(cTel);
		contact.setCVideo(cVideo);		
	//	contactService.saveOrUpdateDeptContact(contact,dId,adminIf);
		this.setResult("success!");
		return "saveOrUpdateContact";
	}

	/**
	 * 通过CId访问数据库获取Contact实例 所需参数:需要获取详细信息的CId
	 * 返回的参数：contactString,contactDeptName,contactDeptDId
	 * 
	 * @return
	 */
	public String findContactByCId() {
	//	Contact contact = contactService.findCotnactByCId(cId);

		//this.setContactDeptDId(contact.getDept().getDId());
		//this.setContactDeptName(contact.getDept().getDName());

		//contact.setDept(null);

//		this.setContactString(JsonUtil.beanToJson(contact));

		return "findContactByCId";
	}

	/**
	 * 删除联系人 所需参数：要删除的联系人ID，所属部门ID 返回的参数：result
	 * 
	 * @return
	 */
	public String deleteContact() {
		service.getTreeNodeById(dId);
		System.out.println("------------删除联系人："+cId+"--------------------");
		contactService.deleteContact(cId,dId);
		this.setResult("deleteSuccess");
		return "deleteContact";
	}
	//根据姓名查询联系人,访问路径：/ag/do/contact_findContactByName.action
	public String findContactByName()
	{
	//	contacts=contactService.findContactByName(cName);
		this.result="共有"+contacts.size()+"条联系人";
		for(Contact c:contacts)
		{
			System.out.println("ContactAction.findContactByName（）：-------------------"+c.getCName()+"  "+c.getCTel()+"-----------------------");
		}
		return "findContactByName";
	}
	private ContactService contactService;



	private String cId;

	private String cName;

	private String dId;
	
	private String cTel;
	
	private String cCellPhone;
	
	private String cFax;
	
	private String cVideo;
	
	private boolean adminIf;

	private String result;
	
	private Contact contact;

	private String contactString;
	
	private List<Contact> contacts;

	public Contact getContact() {
		return contact;
	}

	public void setContact(Contact contact) {
		this.contact = contact;
	}

	public ContactAction() {
		super();
	}

	public ContactAction(ContactService contactService) {
		this.contactService = contactService;
	}

	public ContactService getContactService() {
		return contactService;
	}

	public void setContactService(ContactService contactService) {
		this.contactService = contactService;
	}

	public String getCId() {
		return cId;
	}

	public void setCId(String id) {
		cId = id;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public String getContactDeptName() {
		return cName;
	}

	public void setContactDeptName(String contactDeptName) {
		this.cName = contactDeptName;
	}

	public String getContactDeptDId() {
		return dId;
	}

	public void setContactDeptDId(String contactDeptDId) {
		this.dId = contactDeptDId;
	}

	public String getContactString() {
		return contactString;
	}

	public void setContactString(String contactString) {
		this.contactString = contactString;
	}



	public String getCName() {
		return cName;
	}

	public void setCName(String name) {
		cName = name;
	}

	public String getDId() {
		return dId;
	}

	public void setDId(String id) {
		dId = id;
	}

	public String getCTel() {
		return cTel;
	}

	public void setCTel(String tel) {
		cTel = tel;
	}

	public String getCCellPhone() {
		return cCellPhone;
	}

	public void setCCellPhone(String cellPhone) {
		cCellPhone = cellPhone;
	}

	public String getCFax() {
		return cFax;
	}

	public void setCFax(String fax) {
		cFax = fax;
	}

	public String getCVideo() {
		return cVideo;
	}

	public void setCVideo(String video) {
		cVideo = video;
	}

	public boolean isAdminIf() {
		return adminIf;
	}

	public void setAdminIf(boolean adminIf) {
		this.adminIf = adminIf;
	}
	public String execute()
	{
		System.out.println("*********************");
		return "OK";
	}
}

